# -- coding: utf-8 --
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time

if __name__ == '__main__':

    from selenium import webdriver
    driver = webdriver.Firefox()
    driver.implicitly_wait(5)
    driver.maximize_window()

    driver.get('http://192.168.44.128:8080/WoniuBoss4.0')
    driver.find_element(By.NAME, 'userName').send_keys('WNCD000')
    driver.find_element(By.NAME, 'userPass').send_keys('woniu123')
    driver.find_element(By.CSS_SELECTOR, '.btn').click()

    driver.get('http://192.168.44.128:8080/WoniuBoss4.0/employee')
    driver.find_element(By.CSS_SELECTOR, 'button.btn-padding:nth-child(1)').click()
    region = driver.find_element(By.CSS_SELECTOR, '#addEmp-form > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > select:nth-child(2)')
    Select(region).select_by_visible_text('西安')
    department = driver.find_element(By.CSS_SELECTOR, '#addEmp-form > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > select:nth-child(2)')
    Select(department).select_by_visible_text('管理部')
    driver.find_element(By.CSS_SELECTOR, '#addEmp-form > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > input:nth-child(2)').send_keys('花花4')
    driver.find_element(By.CSS_SELECTOR, '#addEmp-form > div:nth-child(1) > div:nth-child(8) > div:nth-child(1) > input:nth-child(2)').send_keys('WNXA201')
    driver.find_element(By.ID, 'addEmpBtn').click()
    driver.find_element(By.CSS_SELECTOR, '.bootbox > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > button:nth-child(1)').click()

    driver.get('http://192.168.44.128:8080/WoniuBoss4.0/user')
    driver.find_element(By.NAME, 'userName').send_keys('WNXA201')
    driver.find_element(By.CSS_SELECTOR, 'button.btn:nth-child(5)').click()
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR, 'button.btn-padding:nth-child(1)').click()
    driver.find_element(By.ID, 'role_tree_22_check').click()
    driver.find_element(By.ID, 'saveSetRole').click()
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR, '.bootbox > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > button:nth-child(1)').click()
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR, '#setRole-modal > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > button:nth-child(1) > span:nth-child(1)').click()

    time.sleep(2)
    driver.find_element(By.PARTIAL_LINK_TEXT, '注销').click()
    time.sleep(2)

    driver.get('http://192.168.44.128:8080/WoniuBoss4.0')
    driver.find_element(By.NAME, 'userName').send_keys('WNXA201')
    driver.find_element(By.NAME, 'userPass').send_keys('woniu123')
    driver.find_element(By.CSS_SELECTOR, '.btn').click()

    time.sleep(2)
    driver.find_element(By.NAME, 'oldPw').send_keys('woniu123')
    driver.find_element(By.NAME, 'newPw1').send_keys('Woniu123456')
    driver.find_element(By.NAME, 'newPw2').send_keys('Woniu123456')
    driver.find_element(By.CSS_SELECTOR, '#panel-password > div:nth-child(2) > button:nth-child(1)').click()
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR, '#panel-password-success > div:nth-child(2) > button:nth-child(1)').click()
    time.sleep(5)
    oldPw = driver.find_element(By.XPATH, '/html/body/div[12]/div/div/div/div[2]/div[2]/div[1]/form/div[1]/input')
    oldPw.click()
    oldPw.clear()
    oldPw.send_keys('woniu123')
    driver.find_element(By.XPATH, '/html/body/div[12]/div/div/div/div[2]/div[2]/div[1]/form/div[2]/input').send_keys('Woniu123456')
    driver.find_element(By.XPATH, '/html/body/div[12]/div/div/div/div[2]/div[2]/div[1]/form/div[3]/input').send_keys('Woniu123456')
    driver.find_element(By.CSS_SELECTOR, '#panel-password2 > div:nth-child(2) > button:nth-child(1)').click()
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR, '#panel-password-success > div:nth-child(2) > button:nth-child(1)').click()
    time.sleep(2)
    driver.get('http://192.168.44.128:8080/WoniuBoss4.0/assets')